<?php
namespace Festivalcnadmin\Controller;
use Think\Controller;

class SearchController extends BaseController {
	/*
	 * 按标题搜索
	 */
	public function index(){
		$key = iconv('gb2312','utf-8',$_GET['key']);
		$article = D(C('TABLE_ARTICLE'));
		$where['title'] = array('LIKE',"%".$key."%");
		$where['state'] = 0;//状态0代表显示，1代表隐藏。
		$result = $article->alias('a')->join('left join fvcn_holiday as h on h.fstvid = a.fstvid')
    			->join('left join fvcn_nettype as n on n.netid = a.netid')
    			->order('a.updatedate desc')->where($where)->select();
		$this->assign('list',$result);
		$this->display('Index/main');
	}

	 /*
     * 内容详细列表显示
     */
    public function main(){
    	$artcle = D(C('TABLE_ARTICLE'));
		$where['state'] = 0;//状态0代表显示，1代表隐藏。
		$fstvid = I("get.fstvid");
    	if(empty($fstvid)){ 
		  $where['a.fstvid'] = 7;//默认为春节
		}else{ 
		  $where['a.fstvid'] = $fstvid;
		}
    	$count = $artcle->alias('a')->join('left join fvcn_holiday as h on h.fstvid = a.fstvid')
    			->join('left join fvcn_nettype as n on n.netid = a.netid')
    			->order('a.id desc')->where($where)->count();
    	//每页显示条数
    	$num = C('MAIN_NUM');
    	$page = new \Think\Page($count,$num);
    	$obj = pagestyle($page);
    	$show = $obj->show();
    	$result = $artcle->alias('a')->join('left join fvcn_holiday as h on h.fstvid = a.fstvid')
    			->join('left join fvcn_nettype as n on n.netid = a.netid')
    			->order('a.id desc')->where($where)->limit($obj->firstRow.','.$obj->listRows)->select();
    	$this->assign('list',$result);
    	$this->assign('page',$show);
    	$this->redirect('Index/main');
    }

}